package com.ruoyi.jjyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.jjyh.domain.JjyhUseraddress;
import com.ruoyi.jjyh.service.IJjyhUseraddressService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户地址Controller
 * 
 * @author ruoyi
 * @date 2020-11-30
 */
@Controller
@RequestMapping("/jjyh/useraddress")
public class JjyhUseraddressController extends BaseController
{
    private String prefix = "jjyh/useraddress";

    @Autowired
    private IJjyhUseraddressService jjyhUseraddressService;

    @RequiresPermissions("jjyh:useraddress:view")
    @GetMapping()
    public String useraddress()
    {
        return prefix + "/useraddress";
    }

    /**
     * 查询用户地址列表
     */
    @RequiresPermissions("jjyh:useraddress:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JjyhUseraddress jjyhUseraddress)
    {
        startPage();
        List<JjyhUseraddress> list = jjyhUseraddressService.selectJjyhUseraddressList(jjyhUseraddress);
        return getDataTable(list);
    }

    /**
     * 导出用户地址列表
     */
    @RequiresPermissions("jjyh:useraddress:export")
    @Log(title = "用户地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JjyhUseraddress jjyhUseraddress)
    {
        List<JjyhUseraddress> list = jjyhUseraddressService.selectJjyhUseraddressList(jjyhUseraddress);
        ExcelUtil<JjyhUseraddress> util = new ExcelUtil<JjyhUseraddress>(JjyhUseraddress.class);
        return util.exportExcel(list, "useraddress");
    }

    /**
     * 新增用户地址
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户地址
     */
    @RequiresPermissions("jjyh:useraddress:add")
    @Log(title = "用户地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JjyhUseraddress jjyhUseraddress)
    {
        return toAjax(jjyhUseraddressService.insertJjyhUseraddress(jjyhUseraddress));
    }

    /**
     * 修改用户地址
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        JjyhUseraddress jjyhUseraddress = jjyhUseraddressService.selectJjyhUseraddressById(id);
        mmap.put("jjyhUseraddress", jjyhUseraddress);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户地址
     */
    @RequiresPermissions("jjyh:useraddress:edit")
    @Log(title = "用户地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JjyhUseraddress jjyhUseraddress)
    {
        return toAjax(jjyhUseraddressService.updateJjyhUseraddress(jjyhUseraddress));
    }

    /**
     * 删除用户地址
     */
    @RequiresPermissions("jjyh:useraddress:remove")
    @Log(title = "用户地址", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jjyhUseraddressService.deleteJjyhUseraddressByIds(ids));
    }
}
